@extends('admin.layout')
@section('content')


<!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
    
     @if(session('info'))
        <div class="alert alert-success alert-dismissable">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
            <h4><i class="icon fa fa-warning"></i> 警告!</h4>
             <ul>
                {{ session('info') }}
             </ul>
            </div>                              
        @endif 
        <!-- Content Header (Page header) -->
        


        <!-- Main content -->
        <section class="content">
            <!-- Small boxes (Stat box) -->
             <div class="row">
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-aqua">
                        <div class="inner">
                            <h3 class="newadd-user">0</h3>
                            <p>用户总数</p>
                        </div>
                        <div class="icon">
                           
                        </div>
                        <a href="{{ url('/admin/user/index') }}" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div><!-- ./col -->
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-green">
                        <div class="inner">
                            <h3 class="comment-num">0<sup style="font-size: 20px"></sup></h3>
                            <p>评论总数</p>
                        </div>
                        <div class="icon">
                            
                        </div>
                        <a href="#" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div><!-- ./col -->
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-yellow">
                        <div class="inner">
                            <h3 class="goods-num">0</h3>
                            <p>文章总数</p>
                        </div>
                        <div class="icon">
                            
                        </div>
                        <a href="#" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div><!-- ./col -->
                <div class="col-lg-3 col-xs-6">
                    <!-- small box -->
                    <div class="small-box bg-red">
                        <div class="inner">
                            <h3 class="edit-num">0</h3>
                            <p>编辑人员</p>
                        </div>
                        <div class="icon">
                            
                        </div>
                        <a href="{{ url('/admin/user/back') }}" class="small-box-footer">更多 <i class="fa fa-arrow-circle-right"></i></a>
                    </div>
                </div><!-- ./col -->
            </div><!-- /.row --> 
            <div class="box box-success">
                        <div class="box-header">
                            <i class="fa fa-comments-o"></i>
                            <h3 class="box-title">评论动态</h3>
                            <div class="box-tools pull-right" data-toggle="tooltip" title="Status">
                                
                            </div>
                        </div>
                        <div class="box-body chat" id="chat-box">
                        </div><!-- /.chat -->
                        <div class="box-footer">
                            <div class="input-group">
                                <input class="form-control" placeholder="向所有用户推送文字消息">
                                <div class="input-group-btn">
                                    <button class="btn btn-success"><i class="fa fa-plus"></i></button>
                                </div>
                            </div>
                        </div>
                    </div><!-- /.box (chat box) -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
 <script type="text/javascript">

 window.onload = function()
{

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }

    });
     
    
 //添加定时器 
    var cmt = setInterval(function()
    {
                // 获取当前对象
                var u = $(".newadd-user");               
                var c = $(".comment-num");               
                var g = $(".goods-num");               
                var e = $(".edit-num");               
                //
                    //发送ajax
                    $.ajax({
                        url:"{{ url('/admin/index/userajax') }}",
                        type:"POST",
                        data:{},
                        dataType:'json',
                        success:function(data){
                               $(u).html(data['u']);
                               $(c).html(data['c']);    
                               $(g).html(data['g']);
                               $(e).html(data['e']);                            
                        }, 
                    });
                   
                   //动态评论
                   $.ajax({
                    url:"{{ url('/admin/index/comajax') }}",
                    type:"POST",
                    data:{},
                    dataType:'json',
                    async:'false',
                    success:function(data){  
                                if(data == "5")
                                {
                                    alert('查询失败');
                                }

                                $('#chat-box').empty();

                                // 遍历data
                                $.each(data, function(id, obj) {
                                    var div = createDiv();
                                    $('#c1cid').html(obj.detail); 
                                    $(div).appendTo($("#chat-box"));


                                    // 创建div
                                    function createDiv()
                                    {
                                        var div = $('<div></div>');
                                        div.addClass('item');
                                        var img = $('<img></img>');
                                        img.addClass('online');
                                        img.attr({
                                            "src":"{{ url('/uploads/1474801650584722.png') }}",
                                            "alt":"user image"
                                        });
                                        img.prependTo(div); 
                                        var p = $('<p></p>');
                                        p.addClass('message');
                                        p.html(obj.detail);
                                        p.insertAfter(img);
                                        var a = $('<a></a>');
                                        a.addClass('name');
                                        a.attr({"href":"#"});
                                        a.html(obj.user_id);
                                        a.appendTo(p);
                                        var small = $('<small></samll>');
                                        small.addClass('text-muted pull-right');
                                        var ctime = getLocalTime(obj.ctime)+"&nbsp";
                                        small.html(ctime);
                                        small.appendTo(a);
                                        var li = $('<i></i>');
                                        li.addClass('fa fa-clock-o');
                                        li.appendTo(small);
                                       
                                        return div;
                                    }
                                    //时间戳转日期函数
                                    function getLocalTime(nS)
                                    {     
                                        return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17);
                                    }


                                })

                    },
                   });
    },2000);//每3秒钟执行一次newadd函数    
}

 </script>
 @endsection